using System;
using System.ComponentModel;
using System.Transactions;

using SIS.ENT;
using SIS.DAL;


namespace SIS.BLL
{

    /// <summary>
    /// The EducationPeriodTableManager class is responsible for managing BO.EducationPeriodTable objects in the system.
    /// </summary>
    [DataObjectAttribute()]
    public class EducationPeriodTableManager
    {

        #region "Public Methods"


        /// <summary>
        /// Gets a list with all EducationPeriodTable objects in the database.
        /// </summary>
        /// <returns>A list with all EducationPeriodTable from the database when the database contains any, or null otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public static EducationPeriodTableList GetList()
        {
            return EducationPeriodTableDB.GetList();
        }

        /// <summary>
        /// Custom
        /// Gets a list with all EducationPeriodTable objects in the database.
        /// </summary>
        /// <returns>A list with all EducationPeriodTable from the database when the database contains any, or null otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public static EducationPeriodTableList GetList(int SchoolKey)
        {
            return EducationPeriodTableDB.GetList(SchoolKey);
        }

        /// <summary>
        /// Gets a single EducationPeriodTable from the database without its data.
        /// </summary>
        /// <param name="educationPeriodKey">The EducationPeriodKey of the EducationPeriodTable in the database.</param>
        /// <returns>A EducationPeriodTable object when the EducationPeriodKey exists in the database, or <see langword="null"/> otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static EducationPeriodTable GetItem(int educationPeriodKey)
        {
            return GetItem(educationPeriodKey, false);
        }

        /// <summary>
        /// Gets a single EducationPeriodTable from the database.
        /// </summary>
        /// <param name="educationPeriodKey">The EducationPeriodKey of the EducationPeriodTable in the database.</param>
        /// <param name="getEducationPeriodTableRecords">Determines whether to load all associated EducationPeriodTable records as well.</param>
        /// <returns>
        /// A EducationPeriodTable object when the EducationPeriodKey exists in the database, or <see langword="null"/> otherwise.
        /// </returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static EducationPeriodTable GetItem(int educationPeriodKey, bool getEducationPeriodTableRecords)
        {
            EducationPeriodTable myEducationPeriodTable = EducationPeriodTableDB.GetItem(educationPeriodKey);
            if (myEducationPeriodTable != null && getEducationPeriodTableRecords)
            {
                myEducationPeriodTable.educationPeriodStandardCourseTables = EducationPeriodStandardCourseTableDB.GetListByEducationPeriodKey(educationPeriodKey);
            }
            return myEducationPeriodTable;
        }

        /// <summary>
        /// Saves a EducationPeriodTable in the database.
        /// </summary>
        /// <param name="myEducationPeriodTable">The EducationPeriodTable instance to save.</param>
        /// <returns>The new EducationPeriodKey if the EducationPeriodTable is new in the database or the existing EducationPeriodKey when an item was updated.</returns>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
        public static int Save(EducationPeriodTable myEducationPeriodTable)
        {
            using (TransactionScope myTransactionScope = new TransactionScope())
            {
                int educationPeriodTableEducationPeriodKey = EducationPeriodTableDB.Save(myEducationPeriodTable);
                //foreach (EducationPeriodStandardCourseTable myEducationPeriodStandardCourseTable in myEducationPeriodTable.educationPeriodStandardCourseTables)
                //{
                //    myEducationPeriodStandardCourseTable.EducationPeriodKey = educationPeriodTableEducationPeriodKey;
                //    EducationPeriodStandardCourseTableDB.Save(myEducationPeriodStandardCourseTable);
                //}

                //  Assign the EducationPeriodTable its new (or existing EducationPeriodKey).
                myEducationPeriodTable.EducationPeriodKey = educationPeriodTableEducationPeriodKey;

                myTransactionScope.Complete();

                return educationPeriodTableEducationPeriodKey;
            }
        }

        /// <summary>
        /// Deletes a EducationPeriodTable from the database.
        /// </summary>
        /// <param name="myEducationPeriodTable">The EducationPeriodTable instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public static bool Delete(EducationPeriodTable myEducationPeriodTable)
        {
            return EducationPeriodTableDB.Delete(myEducationPeriodTable.EducationPeriodKey);
        }

        /// <summary>
        /// Custom
        /// Deletes a EducationPeriodTable from the database.
        /// </summary>
        /// <param name="int EducationPeriodKey">The EducationPeriodTable instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public static bool Delete(int EducationPeriodKey)
        {
            return EducationPeriodTableDB.Delete(EducationPeriodKey);
        }

        #endregion

    }

}
